from typing import List


class Solution:
    def countKDifference(self, nums: List[int], k: int) -> int:
        size = len(nums)
        ans = 0
        for i in range(size):
            for j in range(i + 1, size):
                if nums[i] - nums[j] == k or nums[j] - nums[i] == k:
                    ans += 1
        return ans


if __name__ == "__main__":
    print(Solution().countKDifference(nums=[1, 2, 2, 1], k=1))  # 4
    print(Solution().countKDifference(nums=[1, 3], k=3))  # 0
    print(Solution().countKDifference(nums=[3, 2, 1, 5, 4], k=2))  # 3
